package com.douhulu.bytedance.common.error;

/**
 * <h2> 奕泽云 - 字节错误处理器基类 </h2>
 *
 * @Author: 奕泽云 - 曾庆雷
 * @Email: 75881401@qq.com
 * @Since: 2022-05-01 13:18
 * CopyRight：山西威斯汀文化传播有限公司
 */
public class ByteErrorException extends Exception {

    private static final long serialVersionUID = -6357149550353160810L;

    private final ByteError error;

    private static final int DEFAULT_ERROR_CODE = -99;

    public ByteErrorException(String message) {
        this(ByteError.builder().errorCode(DEFAULT_ERROR_CODE).description(message).build());
    }

    public ByteErrorException(ByteError error) {
        super(error.toString());
        this.error = error;
    }

    public ByteErrorException(ByteError error, Throwable cause) {
        super(error.toString(), cause);
        this.error = error;
    }

    public ByteErrorException(Throwable cause) {
        super(cause.getMessage(), cause);
        this.error = ByteError.builder().errorCode(DEFAULT_ERROR_CODE).description(cause.getMessage()).build();
    }

    public ByteError getError() {
        return this.error;
    }
}
